#pragma once

//see http://scottbilas.com/publications/gem-singleton/

#include <cassert>

template <typename T> class Singleton
{
	static T* mSingleton;

public:
	Singleton()
	{
		assert( !mSingleton);
		mSingleton = static_cast <T*> (this);
	}

	~Singleton()
	{
		assert(mSingleton); 
		mSingleton = 0; 
	}

	static T& GetSingleton()
	{ 
		assert(mSingleton); 
		return *mSingleton; 
	}

	static T* GetSingletonPtr()
	{ 
		return mSingleton; 
	}

	static void Release()
	{
		assert(mSingleton);
		delete mSingleton;
		mSingleton = nullptr;
	}
};

template <typename T> T* Singleton <T>::mSingleton = nullptr;
